package com.sfexpress.mycatweb.service.monitor;

import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Mem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sfexpress.mycatweb.entity.monitor.BasicMonitorInfo;
import com.sfexpress.mycatweb.entity.monitor.CpuStat;
import com.sfexpress.mycatweb.entity.monitor.MemStat;
import com.sfexpress.mycatweb.entity.monitor.NetStat;
import com.sfexpress.mycatweb.monitor.mock.SigarMonitor;

@Service
public class MockBasicMonitorService implements BasicMonitorService {
	
	@Autowired
	private SigarMonitor sigarMonitor;

	@Override
	public BasicMonitorInfo getBasicMonitorInfo(String host) throws Exception {
		CpuPerc cpuInfo =  sigarMonitor.getCpuInfo();
		Mem memInfo = sigarMonitor.getMemoryInfo();
		NetStat netInfo = sigarMonitor.getNetworkInfo(host);
		BasicMonitorInfo info = new BasicMonitorInfo();
		info.setCpuInfo(CpuStat.transform(cpuInfo));
		info.setMemInfo(MemStat.transform(memInfo));
		info.setNetInfo(netInfo);
		return info;
	}


}
